export function hasClass(el,className){
	let reg = new RegExp('(^|\\s)'+className+'(\\s|$)')
	return reg.test(el.className)
}

export function addClass(el,className){
	if (hasClass(el,className)){
		return
	}

	let newClass = el.className.split(' ')
	newClass.push(className)
	el.className = newClass.join(' ') // 数据结构转字符串，json和数组应该都适用吧

 }

 
 function getData(el,name,val){
 	const prefix = 'data-'
 	if(val){
 		return el.setAttribute(prefix+name,val)
 	}
 	return el.getAttribute(prefix+name)
 }
export {getData}

export function trimStr(str){
	return str.replace(/(^\s*)|(\s*$)/g,"")
}

//find elements sibling
export function classSiblings(el,className){

	let eles = []
	let  preEles = el.previousElementSibling
	while(preEles){
		if(hasClass(preEles,className)){
			eles.push(preEles)
		}
        
		preEles = preEles.previousElementSibling
	}
	eles.reverse()
//	eles.push(el)
	let nextEles = el.nextElementSibling
	while(nextEles){
		if(hasClass(nextEles,className)){
			eles.push(nextEles)
		}
		nextEles = nextEles.nextElementSibling
	}
	return eles;
}

